// @author: caoshi
// @date: 2021-05-04 17:46
// 服务器端
package main

import (
	"fmt"
	"net"
)

func main() {
	addr, _ := net.ResolveTCPAddr("tcp4", "localhost:8899")
	lis, _ := net.ListenTCP("tcp4", addr)

	for {
		conn, _ := lis.Accept()
		go serverAccept(conn)
	}

}

func serverAccept(conn net.Conn) {
	data := make([]byte, 1024)
	// 接收信息
	count, _ := conn.Read(data)
	fmt.Println("服务端已接收到信息: ", string(data[:count]))

	// 发送信息
	conn.Write(append([]byte("服务器发送:"), data[:count]...))

	conn.Close()
}
